package bme.data.datatypes {
	import flash.utils.Dictionary;
	import bme.data.BRC_DataType;

	/**
	 * 	Camp hosted_by_camp;
	Object location_point;
	Art located_at_art;
	String description;
	String title;
	String url;
	Object year;
	boolean all_day;
	int id;
	String print_description;
	Occurrence[] occurrence_set;
	Object[] location_track;
	boolean check_location;
	String slug;
	String other_location;
	 * @author Rendall
	 */
	public class BRC_Event extends BRC_DataType {
		public var year : BRC_Year;
		public var location_point : BRC_Location;
		public var location_track : BRC_Location;

		public var hosted_by_camp : BRC_Camp;
		public var located_at_art : BRC_Art;

		public var occurrence_set : BRC_OccurrenceSet;

		public var description : String;
		public var title : String;
		public var url : String;
		public var all_day : Boolean;
		public var id : uint;
		public var print_description : String;

		public var check_location : Boolean;
		public var slug : String;
		public var other_location : String;

		private static var _events : Array;
		private static var eventsDict:Dictionary;
		private static var lastAdded : BRC_Event;

		/**
		 * Event Constructor
		 */
		public function BRC_Event(dataObj : Object = null) {
			super(dataObj);			
			if (!eventsDict) eventsDict = new Dictionary();
		}

		override protected function setProperty(property : String, value : *) : void {
			if (lastAdded != this && events.indexOf(this) == -1) {
				events.push(this);	
				lastAdded = this;
			}
			
			switch (property) {
				case "occurrence_set":
					occurrence_set = new BRC_OccurrenceSet(value);
					break;
				case "id" :
					eventsDict[value] = this; 
				default:
					super.setProperty(property, value);
			}
		}

		public function toString() : String {
			return "[BRC_Event id:" + id + ", title: " + title + ", " + hosted_by_camp + "]";
		}

		static public function get events() : Array {
			if (!_events) _events = new Array();
			return _events;
		}

		public static function getEventByID(index : uint) : BRC_Event {
			trace("\n BRC_Event.getEventByID( index:" + index + ")");
			return eventsDict[index];
		}
	}
}
